// 引入 Express
const express = require("express");
const { createProxyMiddleware } = require('http-proxy-middleware');
const history = require('connect-history-api-fallback');


// 创建 Express 应用
const app = express();

app.use(history({
    // rewrites: [
    //     { from: /^\/content.*$/, to: (context) => context.parsedUrl.path }
    // ] // 哪来回哪去
}))

const proxyMiddleware = createProxyMiddleware({
  target: 'https://apifoxmock.com/m1/4728220-0-default/api',
  changeOrigin: true,
  pathRewrite: {'^/dev' : ''}
});
app.use('/dev', proxyMiddleware);

// 配置静态资源
app.use(express.static(__dirname + '/public'))

// 启动服务器
const PORT = 3000;
// 绑定端口监听
app.listen(PORT, () => {
  console.log(`本地服务启动成功， http://localhost:${PORT}`);
});